$(document).ready(function() {
	//ajaxform
	var options = { 
		beforeSubmit:showRequest,//表单验证方式
        success:showResponse  // post-submit callback 
    }; 

    $('#ajaxForm').ajaxForm(options); 

    function showResponse(responseText, statusText)  {

		if (statusText == 'success') {
			var responseText=eval('('+responseText+')');
			if(responseText.state != 'SUCCESS'){
				responseText.message = responseText.state;
			}
			msgBox(responseText.state , responseText.message , responseText.url);			
		}else{
			msgBox('','服务器错误','');
		}
	} 

	function showRequest(){
		 return $("form.form-validata").valid();
	}

	//validation验证
	$("form.form-validata").validate({
		errorElement: "span",
        errorClass: "help-inline error",
	})

}); 

function uploadImage(url , domid){
	art.dialog.data('domid', domid);
	art.dialog.open(url,{
	lock:true,
	title:'上传图片',
	width:500,
	height:300,
	});
}

function delImage(domid){
	$("#"+domid).val("");
	$("#"+domid+"_src").attr('src','/tpl/static/image/image.jpg');
}

function selectAD(url , domid){
	art.dialog.data('domid', domid);
	art.dialog.open(url,{
	lock:true,
	title:'选择推广素材',
	width:500,
	height:300,
	});
}

function msgBox(stats , msgContent , url){
	
	if(stats == 'SUCCESS'){
		iconStr = 'succeed';
		var timer;
		art.dialog({
			init : function(){
				var that = this, i = 3;
				var fn = function () {
					that.title(i + '秒后关闭');
					!i && that.close();
					i --;
				};
				timer = setInterval(fn, 1000);
				fn();
				},
			icon : iconStr,
			content : msgContent,
			close: function () {
				clearInterval(timer);
				if(url==''){
					window.location.reload();
				}else{
					window.location.href = url;	
				}				
			},
			lock : true
		})
	}else{
		iconStr = 'error';
		art.dialog({
			title : '消息提示',
			 icon : iconStr,
		  content : msgContent,
		     lock : true
		})
	}		
}

function CheckAll(form){
  for (var i=0;i<form.elements.length;i++){
    var e = form.elements[i];
  	if (e.name != 'chkall'){
	e.checked = form.checkall.checked;
	}
   }
}

function InfoUploadImage(url , domid){
	if($("#piclist li").length>=5){
		alert('图片数量超过5个');
		return false;
	}
	art.dialog.data('domid', domid);
	art.dialog.open(url,{
	lock:true,
	title:'上传图片',
	width:500,
	height:300,
	});
}

function select_company(url){
	art.dialog.open(url,{
	lock:true,
	title:'选择企业',
	width:600,
	height:400,
	});
}

function sel(title , url , domid , width, height){
	art.dialog.data('domid', domid);
	art.dialog.open(url,{
	title:title,
	lock:true,
	width:width,
	height:height,
	});
}